/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.task.dao;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.tech15.task.model.*;
import com.tech15.task.dao.*;
import com.tech15.task.service.*;
import com.tech15.task.vo.query.*;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */


import static cn.org.rapid_framework.util.ObjectUtils.*;
import org.springframework.stereotype.Repository;

@Repository
public class TaskProcessDao extends BaseHibernateDao<TaskProcess,Long>{

	public Class getEntityClass() {
		return TaskProcess.class;
	}
	
	public Page findByPageRequest(PageRequest<Map> pageRequest) {
		//XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
		// [column]为字符串拼接, {column}为使用占位符. 以下为图方便采用sql拼接,适用性能要求不高的应用,使用占位符方式可以优化性能. 
		// [column] 为PageRequest.getFilters()中的key
		String sql = "select t from TaskProcess t where 1=1 "
				+ "/~ and t.taskid = '[taskid]' ~/"
				+ "/~ and t.wfnid = '[wfnid]' ~/"
				+ "/~ and t.nodename = '[nodename]' ~/"
				+ "/~ and t.hanlder = '[hanlder]' ~/"
				+ "/~ and t.tasktime = '[tasktime]' ~/"
				+ "/~ and t.hanldtime = '[hanldtime]' ~/"
				+ "/~ and t.hanldresult = '[hanldresult]' ~/"
				+ "/~ and t.opttype = '[opttype]' ~/"
				+ "/~ and t.hanldetype = '[hanldetype]' ~/"
				+ "/~ and t.hanldestate = '[hanldestate]' ~/"
				+ "/~ order by [sortColumns] ~/";
		return pageQuery(sql,pageRequest);
	}
	
	public Page findPage(TaskProcessQuery query) {
		String sql = "select t from TaskProcess t where 1=1 "
			  	+ "/~ and t.taskid = {taskid} ~/"
			  	+ "/~ and t.wfnid = {wfnid} ~/"
			  	+ "/~ and t.nodename = {nodename} ~/"
			  	+ "/~ and t.hanlder = {hanlder} ~/"
				+ "/~ and t.tasktime >= {tasktimeBegin} ~/"
				+ "/~ and t.tasktime <= {tasktimeEnd} ~/"
				+ "/~ and t.hanldtime >= {hanldtimeBegin} ~/"
				+ "/~ and t.hanldtime <= {hanldtimeEnd} ~/"
			  	+ "/~ and t.hanldresult = {hanldresult} ~/"
			  	+ "/~ and t.opttype = {opttype} ~/"
			  	+ "/~ and t.hanldetype = {hanldetype} ~/"
			  	+ "/~ and t.hanldestate = {hanldestate} ~/"
				+ "/~ order by [sortColumns] ~/";
				
		return pageQuery(sql,query);
	}

	public List<TaskProcess> findByTaskid(Long taskid) {
		String sql = "select t.*,t1.realname as username,t2.realname as zprxm from task_process t " +
				" left join sys_user t1 on t.hanlder=t1.userid " +
				" left join sys_user t2 on t.zpr=t2.userid " +
				" where t.taskid="+taskid+" order by t.tasktime asc";
		Map map = new HashMap();
		map.put("tpid","Long");
		map.put("hanlder","Long");
		map.put("username","String");
		map.put("tasktime","Timestamp");
		map.put("hanldtime","Timestamp");
		map.put("hanldresult","String");
		map.put("opttype","Integer");
		map.put("hanldetype","Integer");
		map.put("hanldestate","Integer");
		map.put("taskaction","Integer");
		map.put("zprxm","String");
		return findSqlAll(sql, map, TaskProcess.class);
	}
	

}
